package org.smartboot.flow.testcase.extension;

import org.smartboot.flow.core.EngineContext;
import org.smartboot.flow.core.ExecutionListener;
import org.smartboot.flow.core.Extensible;
import org.smartboot.flow.core.parser.ExtensionAttrParser;
import org.smartboot.flow.core.util.AuxiliaryUtils;

/**
 * @author qinluo
 * @date 2023-03-31 18:06:21
 * @since 1.0.0
 */
public class EnvcheckExtensionAttrParser implements ExtensionAttrParser {

    @Override
    public String prefix() {
        return "check";
    }

    @Override
    public boolean allowOverride() {
        return true;
    }

    @Override
    public ExecutionListener getListener() {
        return CheckExecutionListener.INSTANCE;
    }

    public static class CheckExecutionListener implements ExecutionListener {

        static final ExecutionListener INSTANCE = new CheckExecutionListener();

        @Override
        public <T, S> void beforeExecute(EngineContext<T, S> ctx, Object object) {

            if (object instanceof Extensible) {
                Extensible extensible = (Extensible) object;
                String value = extensible.getValue("check");

                if (AuxiliaryUtils.isBlank(value)) {
                    return;
                }

                System.out.println("check command " + value);
            }
        }
    }
}
